<?php
declare (strict_types=1);

namespace app\command;

use app\model\order\OrderModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 指令-检测订单过期-取消
 * Class CheckOrderOut
 * @package app\command
 */
class CheckOrderOut extends Command
{
    protected function configure()
    {
        $this->setName('check_order_out_timeout')->setDescription('the check_order_out_timeout command');
    }

    /**
     * 取消订单（正常订单未付款  拼团订单未成团）
     * @param Input $input
     * @param Output $output
     * @return int|void|null
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function execute(Input $input, Output $output)
    {
        $order_model = new OrderModel();//删除
        $order_list = $order_model->getCancelOrder();
        if (!empty($order_list)) {
            foreach ($order_list as $key => $value) {
                $order_model->cancelOrder($value['id']);
            }
        }
        echo "success";
    }
}
